﻿using System;
using CatClient;
using CatClient.Message.Spi.Internals;
using CatClient.Util;
using PostSharp.Aspects;
using PostSharp.Aspects.Internals;
using PostSharp.Extensibility;

namespace PsCat.Aspet
{
    // Token: 0x02000009 RID: 9
    [HasInheritedAttribute(new long[]
    {

    })]
    [Serializable]
    public class PureContextCatAttribute : CatBaseAttribute
    {
        // Token: 0x06000023 RID: 35 RVA: 0x00002830 File Offset: 0x00000A30
        public PureContextCatAttribute()
        {
            //base.ApplyToStateMachine = true;
        }

        // Token: 0x06000024 RID: 36 RVA: 0x00002840 File Offset: 0x00000A40
        [HasInheritedAttribute(new long[]
        {
            -966559710620335241L
        })]
        [MethodExecutionAdviceOptimization(MethodExecutionAdviceOptimizations.IgnoreGetMethod | MethodExecutionAdviceOptimizations.IgnoreSetFlowBehavior | MethodExecutionAdviceOptimizations.IgnoreGetArguments | MethodExecutionAdviceOptimizations.IgnoreSetArguments | MethodExecutionAdviceOptimizations.IgnoreGetInstance | MethodExecutionAdviceOptimizations.IgnoreSetInstance | MethodExecutionAdviceOptimizations.IgnoreGetException | MethodExecutionAdviceOptimizations.IgnoreGetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetReturnValue | MethodExecutionAdviceOptimizations.IgnoreGetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreSetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreGetYieldValue | MethodExecutionAdviceOptimizations.IgnoreSetYieldValue | MethodExecutionAdviceOptimizations.IgnoreGetDeclarationIdentifier | MethodExecutionAdviceOptimizations.IgnoreEventArgs)]
        public override void OnEntry(MethodExecutionArgs args)
        {
            try
            {
                if (base.AsyncMethod)
                {
                    if (Cat.IsInitializedWithoutSetup())
                    {
                        DefaultMessageManager defaultMessageManager = (DefaultMessageManager)Cat.GetManager();
                        this._currentKey = ((defaultMessageManager != null) ? defaultMessageManager.GetCurrent() : null);
                    }
                }
            }
            catch (Exception ex)
            {
                LogInfoWriter.GetInstance("Cat", 0, LogInfoWriter.LogLayout.Default).Error(ex.Message, ex);
            }
        }

        // Token: 0x06000025 RID: 37 RVA: 0x000028A8 File Offset: 0x00000AA8
        [HasInheritedAttribute(new long[]
        {
            -966559708541291272L
        })]
        [MethodExecutionAdviceOptimization(MethodExecutionAdviceOptimizations.IgnoreGetMethod | MethodExecutionAdviceOptimizations.IgnoreSetFlowBehavior | MethodExecutionAdviceOptimizations.IgnoreGetArguments | MethodExecutionAdviceOptimizations.IgnoreSetArguments | MethodExecutionAdviceOptimizations.IgnoreGetInstance | MethodExecutionAdviceOptimizations.IgnoreSetInstance | MethodExecutionAdviceOptimizations.IgnoreGetException | MethodExecutionAdviceOptimizations.IgnoreGetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetReturnValue | MethodExecutionAdviceOptimizations.IgnoreGetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreSetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreGetYieldValue | MethodExecutionAdviceOptimizations.IgnoreSetYieldValue | MethodExecutionAdviceOptimizations.IgnoreGetDeclarationIdentifier | MethodExecutionAdviceOptimizations.IgnoreEventArgs)]
        public override void OnResume(MethodExecutionArgs args)
        {
            if (base.AsyncMethod && this._currentKey != null)
            {
                DefaultMessageManager defaultMessageManager = (DefaultMessageManager)Cat.GetManager();
                if (defaultMessageManager == null)
                {
                    return;
                }
                defaultMessageManager.SetCurrent(this._currentKey);
            }
        }

        // Token: 0x0400000E RID: 14
        private DefaultMessageManager.CurrentKey _currentKey;
    }
}
